package com.zhugang.week13.queue;

import org.junit.Test;

import java.util.LinkedList;

import static org.junit.Assert.assertEquals;

/**
 * @program algorithms
 * @description: Queue
 * @author: chanzhugang
 * @create: 2022/10/08 18:33
 */
public class Queue<T> {

    /**
     * 自定义队列：先进先出
     */
    LinkedList<T> list = new LinkedList<>();

    /**
     * 入队：尾部入
     *
     * @param e
     */
    public void enqueue(T e) {
        list.add(e);
    }

    /**
     * 出队：头部出
     *
     * @return
     */
    public T dequeue() {
        return list.remove();
    }

    @Test
    public void test() {
        var queue = new Queue<>();
        queue.enqueue(1);
        queue.enqueue(2);
        queue.enqueue(3);
        queue.enqueue(4);

        assertEquals(1, queue.dequeue());
        assertEquals(2, queue.dequeue());
        assertEquals(3, queue.dequeue());
        assertEquals(4, queue.dequeue());

    }
}